package com.example.cacheredis.controller;

import com.example.cacheredis.pojo.Employee;
import com.example.cacheredis.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping("/getAllEmp")
    public List<Employee> getAllEmployee() {
        return this.employeeService.findAllEmployees();
    }

    @GetMapping("/getById/{employeeId}")
    public Employee getEmployeeById(@PathVariable Integer employeeId) {
        return this.employeeService.findEmpById(employeeId);
    }

    @GetMapping("/getByDeptId/{departmentId}")
    public List<Employee> getEmployeeByDeptId(@PathVariable Integer departmentId) {
        return this.employeeService.findEmpByDeptId(departmentId);
    }

    @GetMapping("/updateEmp")
    public String updateEmp(Employee employee) {
        this.employeeService.updateEmployee(employee);
        return "ok";
    }

    @GetMapping("/deleteEmp/{employeeId}")
    public String deleteEmp(@PathVariable Integer employeeId) {
        this.employeeService.deleteEmpById(employeeId);
        return "ok";
    }

    @GetMapping("/getEmpByEmpName/{employeeName}")
    public Employee getEmpByEmpName(@PathVariable String employeeName) {
        return this.employeeService.findEmployeeByName(employeeName);
    }

    @GetMapping("/getEmpByAddress/{address}")
    public Employee getEmpByAddress(@PathVariable String address) {
        return this.employeeService.findEmployeeByAddress(address);
    }


}
